<!DOCTYPE html>
<html>
<head>
    <title>文档下载</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="dist/lib/weui.css">
    <link rel="stylesheet" href="dist/css/build.css">
    <link rel="stylesheet" href="dist/css/jquery-weui.css">

    <style>
        body {
            background: #f5f5f5
        }

        .weui-cells.weui-cells_form {
            background: #fff;
            /*-moz-box-shadow: 2px 2px 5px #333333;*/
            /*-webkit-box-shadow: 0px 2px 15px #eee;*/
            /*box-shadow: 0px 2px 15px #eee;*/

        }

        .weui-media-box_appmsg {
            align-items: normal;
        }

        .weui-media-box__bd span {
            color: #aaa;
            font-size: 14px;
        }

        .weui-media-box_appmsg .weui-media-box__hd {
            background: #417DFF;
            border-radius: 3px;
            overflow: hidden;
            width: 52px;
        }

        .weui-media-box.weui-media-box_appmsg {
            padding-bottom: 0px;
        }

        .weui-media-box_appmsg .weui-media-box__hd:after {
            content: '文件';
            color: #fff;
        }

        .cont {
            width: 100%;
            display: block;
        }

        .btn {
            padding-top: 10px;
            padding-bottom: 10px;
            padding-left: 78px;
            display: block;
            /*text-align: right;*/
        }

        .btn a {
            color: #417DFF;
            /*width: 70px;*/
            height: 28px;
            background: #fff;
            text-align: left;
            border: none;
            /*color: #666;*/
            margin-right: 10px;
            border-radius: 3px;
            font-size: 14.5px;
            display: block;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .btn a.lan {
            background: #fff;
            color: #417DFF;
            border: 1px solid #417DFF;
            position: relative;
        }

        .btn:before {
            content: " ";
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            height: 1px;
            border-top: 1px solid #E5E5E5;
            color: #E5E5E5;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }

        .hide {
            display: none;
        }

        .weui-media-box__desc.dowm {
            color: #888;
            font-size: 14px;
            line-height: 1.5;
            overflow: no-content;
            text-overflow: inherit;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1000;
        }

        /*微信下载提示*/
        .wxtip {
            background: rgba(0, 0, 0, 0.8);
            text-align: center;
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            z-index: 998;
            display: none;
        }

        .wxtip-icon {
            width: 52px;
            height: 67px;
            background: url() no-repeat;
            display: block;
            position: absolute;
            right: 30px;
            top: 20px;
        }

        .wxtip-txt {
            color: #fff;
            font-size: 18px;
            line-height: 1.5;
            width: 140px;
            margin: 0 auto;
            padding: 20px;
            margin-top: 68px;
            border: 1px dotted #eee;
            border-radius: 50%;
        }

        .weui-loadmore_line .weui-loadmore__tips {
            background: #f5f5f5;
        }

        .ico {
            width: 18px;
            height: 18px;
            display: inline-block;
            float: left;
            margin-top: 4px;
            margin-right: 5px;
        }

    </style>
</head>

<body>
<!--微信下载 Star-->
<div class="wxtip" id="JweixinTip">
    <span class="wxtip-icon"></span>
    <p class="wxtip-txt">点击右上角<br>选择在浏览器中打开~~</p>
</div>
<!--微信下载 End-->
<div class="page__bd">

    <!--Vue 模板内容 开始-->
    <div id="orderlist">
        <div class="weui-panel weui-panel_access" v-for="item in items">

            <div class="weui-panel__bd">

                <div class="cont" style="display: block">

                    <div class="weui-media-box weui-media-box_appmsg">

                        <!--图片 star-->
                        <div class="weui-media-box__hd">
                            <!--<img class="weui-media-box__thumb" src="" alt="">-->
                        </div>
                        <!--图片 end-->

                        <div class="weui-media-box__bd">
                            <h4 class="weui-media-box__title">{{item.title}}</h4>
                            <p class="weui-media-box__desc dowm">{{item.name}}</p>
                            <span>{{item.category}}</span>
                        </div>


                    </div>

                </div>
                <div class="btn" id="btn" v-html="item.download"></div>
            </div>
        </div>
    </div>
    <!--Vue 模板内容 结束-->

    <!--加载 Star-->
    <div class="weui-loadmore hide">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">正在加载</span>
    </div>
    <!--加载 End-->
</div>
<script src="dist/lib/jquery-2.1.4.js"></script>
<script src="dist/lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="dist/js/jquery-weui.js"></script>
<script src="dist/lib/vue.min.js"></script>
<script src="dist/lib/http.js"></script>
<script src="dist/lib/jquery.cookie.js"></script>


<script>

    /**
     * js获取HTML ？后面传值
     */
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                // theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    /**
     * js获取HTML ？后面传值 的调用方法
     */
    var Request = new Object();
    Request = GetRequest();
    var id;
    id = Request['id'];

    $(document).attr("title", Request['title']);

    //vue 模板替换
    var news = new Vue({
        el: '#orderlist',
        data: {
            items: [] //列表信息流数据
        }
    });

    /**
     * 微信点击下载按钮判断
     */
    var ua = navigator.userAgent.toLowerCase();

    function WXLRQ() {

        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true
        } else {
            return false
        }
    }

    function openWx(url, id) {
        if (WXLRQ()) {
            $("#JweixinTip").show();
        } else {
            /**
             * 判断用户是否登录
             */
            $http.getUserSignIn(true, 'document_details.html', 'id=' + Request['id']);
            /**
             * 提交用户信息
             */
            getDoload(id);
            /**
             * 开始下载
             */
            var myhref = document.getElementsByTagName("a");
            window.location.href = myhref[url].title;

        }
    }

    /**
     * 点击空白地方隐藏弹框
     */
    $("#JweixinTip").click(function () {
        $("#JweixinTip").hide();
    });


    getData(id);

    /**
     * 得到详情数据
     * @param id
     */
    function getData(id) {
        if (id == null || id == undefined || id == '') {

            return $(".page__bd").append(
                '<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">没有找到相应的文件</span></div>'
            )
        } else {
            $http.post($http.wdFindByCondition(id)).then(function (data) {

                if (data.success == true) {
                    console.log(id)
                    var getMyData = {
                        id: data['data'][0]['id'],
                        title: data['data'][0]['title'],
                        name: data['data'][0]['name'],
                        outline: data['data'][0]['outline'],
                        category: data['data'][0]['category'],
                        // download: dateUtils.downloadUrl(data['data'][0]['id'])
                        download: getDocumentAttachment(data['data'][0]['id'])
                    }
                    news.items = news.items.concat(getMyData);

                } else {
                    ListID = -1;
                    return $(".page__bd").append(
                        '<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>'
                    )

                }

            }, function (err) {
                console.log(err);
                return err;
            });
        }

    }

    function getDocumentAttachment(id) {
        var obj = '';

        $http.post($http.DocumentAttachment(id)).then(function (data) {
            if (data.success == true) {
                var text = [];
                $.each(data['data'], function (index, array) {
                    text[index] = '<a href="javascript:openWx(' + index + ',' + id + ');" title="' + array['url'] + '">' + '<img class="ico" src=""></img>' + array['name'] + '</a>'
                });
                obj = text.join('');
            } else {
                obj = '<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无下载数据</span></div>'
            }

        }, function (err) {
            obj = "错误";
            console.log(err);
            // return err;
        });

        return obj;

    }

    /**
     * 下载文档
     */
    function getDoload(id) {
        rs = {
            docId: id,//文档id
            lawyerId: $http.getUserSignIn().id,//律师id
            lawyerName: $http.getUserSignIn().name,//律师姓名
            docRole: $http.getUserSignIn().roleId,//文档角色
            lawyerRole: $http.getUserSignIn().roleName,//律师角色
            wechatId: $http.getUserSignIn().phone,
        }
        $http.post($http.DownloadDoc(rs)).then(function (data) {
        }, function (err) {
            console.log(err);
            return err;
        });
    }

</script>
</body>
</html>
